﻿using System;

namespace Taste.Internal
{
    internal class InitialState<TState, TTrigger> : ICurrentStateImpl<TState, TTrigger>
        where TState : struct
        where TTrigger : struct
    {
        private const string ErrorMessage = "State Machine must be started first";

        public InitialState()
        {
        }

        public TState? PreviousStateName { get { return null; } }
        public TState Name { get { return default(TState); } }
        public object UserData { get { return null; } }

        public bool Leave(object userData = null)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public void ReportError(Exception error)
        {
        }

        public void OnFired(TTrigger triggerName, Action effect, Func<bool> condition = null)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public void OnFired<TParam>(TTrigger triggerName, Action<TParam> effect, Func<TParam, bool> condition = null)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public void Ignore(TTrigger triggerName)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public void BeforeNextState(Action action)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public void OnError(Action<IStateError<TState>> action)
        {
            throw new InvalidOperationException(ErrorMessage);
        }

        public bool? CanFire(TTrigger triggerName, object parameter)
        {
            return null;
        }

        public bool Fire(TTrigger triggerName, object parameter)
        {
            return false;
        }

        public void ErrorHappened(IStateError<TState> error)
        {
        }

        public void GoingToNextState()
        {       
        }

        public void Entered()
        {
        }

        public void Leaving(IStateTransition<TState> transition)
        {
        }
    }
}
